console.log('tax injected');

// import './chongqing-invoice.js';

import { getNationData, fillInput } from "./utils.js"

import { fillHspj } from './options/hsqj.js';
import { fillinputCwbb } from './options/cwbb.js'
import { autoInputAccount } from './options/autoLogin.js';

var baseInfoCache;

window.postMessage(
  {
    event: 'getBaseInfo'
  },
  '*'
);

// 监听事件
window.addEventListener(
  'message',
  async function ({ data }) {
    // 只监听来自于content script的信息
    if (data.sender !== 'content-script') {
      return false;
    }
    // 财务报表 + 汇算清缴
    if (data.event === 'setSaasData') {
      data = data.data;
      let sheet = data.saasData.sheet;
      if (sheet == 'sds' || sheet == 'zzs') {
        fillInput(data, sheet);
      } else if (sheet.includes('hsqj')) {
        fillHspj(data, sheet);
        return true;
      } else {
        fillinputCwbb(data, sheet);
      }
    }
    // 会计制度
    if (data.event === 'getNationData') {
      getNationData(data.data);
    }
    // 基本信息
    if (data.event === 'getBaseInfo') {
      window.baseInfoCache = data.data;
      autoInputAccount(data.data);
    }
  },
  false
);



